perm filename DEMO.MF[MF,DEK] blob
sn#751797 filedate 1984-04-26 generic text, type T, neo UTF8
% this file was used in the lecture on coordinates
% (but these comments were added later)
delimiters (); % this makes "(" and ")" act like parentheses
vardef z@#=(x@#,y@#) enddef; % now, e.g., z1a stands for (x1a,y1a)
edges e; % now "e" is a variable of type "edges"
e=nulledges; % and it has been set equal to "nulledges"
% "draw" and "erase" add data to edges e
def draw expr x = addto e contour x withweight 1 enddef;
def erase expr x = addto e contour x withweight -1 enddef;
openwindow 1 from (0,0) to (400,450) at (-100,200); % start screen display
smoothing:=1; autorounding:=2; % make the curves round nicely
charcode:=96; % we'll create a font having characters numbered 96, 97, ...
tracingedges:=1; tracingonline:=1; % METAFONT will show its edges online
hppp:=300/72.27; % horizontal pixels per point on the QMS
vppp:=hppp; % vertical pixels per point on the QMS
pausing:=1; % METAFONT will pause at each line before reading it
h=1; v=1; % set the horizontal and vertical scale factors to 1
z1=(6h,0); % this defines point number 1; we have x1=6*h, y1=0
z2=(0,8v); % x2=0 and y2=8*v
z3=(4h,11v); % and so on
z4=(10h,8v);
z5=(17h,9v);
z6=(18h,2v);
draw z1..z2..z3..z4..z5..z6..cycle; % connect the six points
% at this point the digitized edges are shown, because tracingedges>0.
% METAFONT types the following, online:
% Tracing edges at line 11: (weight -1)
% (2,10)(2,11)(6,11)(6,10)(7,10)(7,9)(9,9)(9,8)(13,8)(13,9)(18,9)(18,8)
% (19,8)(19,3)(18,3)(18,1)(17,1)(17,0)(15,0)(15,-1)(8,-1)(8,0)(5,0)(5,1)
% (3,1)(3,2)(2,2)(2,3)(1,3)(1,5)(0,5)(0,9)(1,9)(1,10).
display e on 1; % show the current edges on the screen in subwindow 1
shipout e; % output the current edges to a font file (as character 96)
e:=nulledges; numeric x[],y[]; % get ready for next demo
h:=3; v:=2; % now horizontal dimensions are tripled; vertical doubled
z1=(6h,0); % those points again, recomputed with new h and v
z2=(0,8v);
z3=(4h,11v);
z4=(10h,8v);
z5=(17h,9v);
z6=(18h,2v);
z0=(9h,3v); % add a "center" point
show z0,z1; % z0 is shown to equal (27,6); and z1=(18,0)
show z1+(1,1); % hence z1+(1,1) equals (19,1)
show z6-z5; % z6-z5 = (18h,2v)-(17h,9v) = (h,-7v) = (3,-14)
z1a-z0=2(z1-z0); % define "a" points that are twice
z2a-z0=2(z2-z0); % as far from z0 as the original ones
z3a-z0=2(z3-z0);
z4a-z0=2(z4-z0);
z5a-z0=2(z5-z0);
z6a-z0=2(z6-z0);
show z1a; % this shows the coordinates of point 1a, namely (9,-6)
draw z1a..z2a..z3a..z4a..z5a..z6a..cycle; % fill in the outer shape
erase z1..z2..z3..z4..z5..z6..cycle; % then erase the inner one
display e on 1; % and show the result on the screen
% now we define a "macro" or "subroutine" that does what we just did
% so that we do it over and over without retyping it each time
def demochar(expr h,v)= % h and v will be parameters to the demochar routine
e:=nulledges; % throw away the previous edges
numeric x[],y[],x[]a,y[]a; % delete values of x[i], y[i], x[i]a, y[i]a
charcode:=charcode+1; % we'll generate the next character number in the font
z1=(6h,0); % recompute those famous six points
z2=(0,8v);
z3=(4h,11v);
z4=(10h,8v);
z5=(17h,9v);
z6=(18h,2v);
z0=(9h,3v); % and their famous center
for n:=1 step 1 until 6: % here's another way to get the "a" points
z[n]a-z0 = 2(z[n]-z0);
endfor
draw z1a..z2a..z3a..z4a..z5a..z6a..cycle;
erase z1..z2..z3..z4..z5..z6..cycle;
display e on 1;
charwd:=40h/hppp; % specify the character width in printer's points
chardw:=40h; % specify the "device width" in pixels
shipout e;
enddef; % end of the macro definition
% now we produce the five characters shown below as they were eventually
% output by the QMS printer
demochar(1,1);
demochar(2,1);
demochar(1,2);
demochar(10,10);
demochar(10,-10); % negative v flips it upside down
end